﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using Infrastructure;
using Infrastructure.Managers;
using RhotCMS.Models;
using Core.Logging;
using Core.Constants;
using RhotCMS.Filters;
using Core.Users;
using Core.Email;

namespace RhotCMS.Controllers
{
    public class RhotCMSController : Controller
    {
        public string UILangName { get; set; }
        public bool IsPreview {get;set;}       
        public bool IsAlowed
        {
            get
            {
                return _isAlowed;
            }
            protected set
            {
                _isAlowed = value;
            }
        }
        
        private bool _isAlowed;

        //to test unity cintroller injection
        protected ILogger _logger;
        //

        protected ICurrentUserService _currentUserService;

        protected PageManager _pageManager;
        protected UserManager _userManager;
        protected CacheManager _cacheManager;
        protected StoreManager _storeManager;
        protected SystemSettingsManager _systemSettingsManager;

        public RhotCMSController(ILogger logger, ICurrentUserService userService)
        {
            IsAlowed = true;
            IsPreview = false;
            _currentUserService = userService;
            _logger = logger;
            UILangName = ConstantsLanguages.STR_DEFAULT_LANGUAGE;
        }

        public ActionResult YouHaveNoPermission()
        {
            return View();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_pageManager != null)
                {
                    _pageManager.Dispose();
                }
                if (_cacheManager != null)
                {
                    _cacheManager.Dispose();
                }
                if (_userManager != null)
                {
                    _userManager.Dispose();
                }
                if (_storeManager != null)
                {
                    _storeManager.Dispose();
                }
                if (_systemSettingsManager != null)
                {
                    _systemSettingsManager.Dispose();
                }
            }
            base.Dispose(disposing);
        }
    }
}
